//
//  SYHttpTools.m
//  BSHOUYIFANG
//
//  Created by 曹雁彬 on 15/11/9.
//  Copyright © 2015年 CYB. All rights reserved.
//

#import "SYHttpTools.h"
#import "AFNetworking.h"
@implementation SYHttpTools
+(instancetype)defaultManager
{
    static SYHttpTools *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[SYHttpTools alloc]init];
    });
    return manager;
}
-(void)get:(NSString *)url success:(void (^)(id success))success
                             error:(void (^)(NSError *error))failure
{
   AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * task, id  responseObject) {
        success(responseObject);
    } failure:^(NSURLSessionDataTask * task, NSError * error) {
        failure(error);
        NSLog(@"是发达");
    }];
}

-(void)post:(NSString *)url parameters:(NSDictionary *)parameters
                               success:(void (^)(id))success
                                 error:(void (^)(NSError *))failure
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:url parameters:parameters success:^(NSURLSessionDataTask * task, id  responseObject) {
        success(responseObject);
        
    } failure:^(NSURLSessionDataTask * task, NSError * error) {
         failure(error);
    }];
    
}

+(void)post:(NSString *)url parameters:(NSDictionary *)parameters
                               success:(void (^)(id))success
                                 error:(void (^)(NSError *))error
{
    SYHttpTools *tools = [[SYHttpTools alloc]init];
    [tools post:url parameters:parameters success:success error:error];
}

+ (void)get:(NSString *)url success:(void (^)(id))success
                              error:(void (^)(NSError *))error
{
    SYHttpTools *tools = [[SYHttpTools alloc]init];
    [tools get:url success:success error:error];
}
@end
